package com.mrtan.service.impl;

import com.mrtan.bean.Stock;
import com.mrtan.mapper.StockMapper;
import com.mrtan.service.StockService;
import com.mrtan.vo.StockInsertVO;
import com.mrtan.vo.StockVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 库存
 * @author 李聪
 * @version 2023/12/8
 */
@Service
public class StockServiceImpl implements StockService {
    @Resource
    private StockMapper stockMapper;
    @Override
    public List<Stock> selectAll(StockVO stockVO) {
        return stockMapper.selectAll(stockVO);
    }

    @Override
    public int updateNumber(StockInsertVO stockInsertVO) {
        Integer number = stockMapper.selectNumber(stockInsertVO.getWarehouseId(), stockInsertVO.getProductId());
        stockInsertVO.setQuantity(number - stockInsertVO.getQuantity());
        return stockMapper.updateByWarehouseId(stockInsertVO);
    }

    @Override
    public List<Stock> showStockProducts(StockVO stockVO) {
        List<Stock> stocks = stockMapper.showStockProducts(stockVO);
        return stocks;
    }
}
